package com.xinli.xinlifm.view.fragment.forum;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.xinli.xinlifm.R;

/**
 *   社交
 * Created by zz on 16-10-12.
 */

public class ForumFragment extends Fragment implements RadioGroup.OnCheckedChangeListener {
    private RadioGroup radioGroup;
    private RadioButton btu1;
    private RadioButton btu2;
    private Froum_JingHuaFragment froum_jingHuaFragment;
    private Froum_NewFragment froum_newFragment;
    FragmentTransaction fragmentTransaction;
    private FragmentTransaction fragmentTransaction1;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_forum,container,false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        fragmentTransaction = getChildFragmentManager().beginTransaction();
        froum_jingHuaFragment = new Froum_JingHuaFragment();
        froum_newFragment = new Froum_NewFragment();
        radioGroup = ((RadioGroup) view.findViewById(R.id.radioGroup));
        btu1 = ((RadioButton) radioGroup.findViewById(R.id.forum_jingHua));
        btu2 = ((RadioButton) radioGroup.findViewById(R.id.forum_new));
        radioGroup.setOnCheckedChangeListener(this);
        onCheckedChanged(radioGroup, R.id.forum_jingHua);
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        btu1.setTextColor(getResources().getColor(R.color.colorLoad));
        btu2.setTextColor(getResources().getColor(R.color.colorLoad));
        fragmentTransaction = getChildFragmentManager().beginTransaction();
        fragmentTransaction1 = getChildFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.forum_container,froum_jingHuaFragment);
        fragmentTransaction1.replace(R.id.forum_container,froum_newFragment);
        switch (i) {
            case R.id.forum_jingHua:
                btu1.setTextColor(getResources().getColor(R.color.forum_default));
                fragmentTransaction.show(froum_jingHuaFragment);
                fragmentTransaction.hide(froum_newFragment);
                fragmentTransaction.commit();
                break;
            case R.id.forum_new:
                btu2.setTextColor(getResources().getColor(R.color.forum_default));
                fragmentTransaction1.show(froum_newFragment);
                fragmentTransaction1.hide(froum_jingHuaFragment);
                fragmentTransaction1.commit();
                break;
        }
    }
}
